package com.es.pay.shopGrade;

import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.es.main.LoginUserBeen;
import com.es.util.excel.ExportExcelJsp;
import com.es.util.excel.ShopGradeOrderBean;
import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.webwork.interceptor.ServletResponseAware;
import com.opensymphony.xwork.ActionSupport;

public class ExceptExcelShopGradeListAction  extends ActionSupport implements ServletRequestAware,ServletResponseAware{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	HttpServletRequest request;
	HttpServletResponse response;
	 
	   public String execute()throws Exception
	   {
		   request.setCharacterEncoding("GB2312");
		   String queryyyyymm = request.getParameter("queryyyyymm")==null?"":request.getParameter("queryyyyymm");
		   String queryShopCode = request.getParameter("queryShopCode")==null?"":request.getParameter("queryShopCode");
		   String queryShopName = request.getParameter("queryShopName")==null?"":request.getParameter("queryShopName");
		   String emp_city_code = request.getParameter("emp_city_code")==null?"":request.getParameter("emp_city_code");
		   String emp_province_code = request.getParameter("emp_province_code")==null?"":request.getParameter("emp_province_code");
		   String emp_area_code = request.getParameter("emp_area_code")==null?"":request.getParameter("emp_area_code");
		   String queryCtmName = request.getParameter("queryCtmName")==null?"":request.getParameter("queryCtmName");
		   
		   LoginUserBeen userBean = (LoginUserBeen)request.getSession(false).getAttribute("loginuser");
		   String role  = userBean.getLoginRole();	
		    
		   if("zongbu1".indexOf(role)>=0){
			}else if("shiyebu".equals(role)){
			}else if("RTM".equals(role)){
				emp_area_code = userBean.getEara_code()==null?"":userBean.getEara_code();
			}else {//CTM&&其他
				emp_area_code = userBean.getEara_code()==null?"":userBean.getEara_code();
				emp_city_code = userBean.getCity_code()==null?"":userBean.getCity_code();
				emp_province_code = userBean.getProvince_code()==null?"":userBean.getProvince_code();
				queryCtmName = userBean.getLoginUserName()==null?"":userBean.getLoginUserName();
			}	
		   
		   ShopGradeBiz  manegeBiz= new ShopGradeBiz();
		   ArrayList<String> param = new ArrayList<String>();
		   param.add(queryyyyymm);
		   param.add(queryCtmName);
		   param.add(queryShopName);
		   param.add(queryShopCode);
		   param.add(emp_area_code);
		   param.add(emp_province_code);
		   param.add(emp_city_code);
		   ArrayList<HashMap<String,String>> list  = manegeBiz.exceptExcelShopGradeList(param);
		   String excelString = ExportExcelJsp.getExcelJspString(list,ShopGradeOrderBean.getShopGradeOrderMap());
			  
			  //String filename="测试";
			  excelString = "<html><head><title></title></head><body > "+excelString+"</body></html>";
			  response.setContentType("application/vnd.ms-excel;charset=gb2312");
			  //response.setHeader("Content-disposition","attachment; filename="+new String(filename.getBytes("gbk"),"iso8859-1")+".xls" );
			  response.getWriter().write(excelString);
		      return "";
	   }
	
	   public void setServletRequest(HttpServletRequest request) {
		     this.request = request;
		   }
	   public void setServletResponse(HttpServletResponse response) {
		    this.response = response;
		  }
}

